package csdn;

import java.util.Scanner;

/**
 * 项目名称：wangxu
 * 类 名 称：字符串序列判定
 * 描 述：https://dream.blog.csdn.net/article/details/129548118
 * 创建时间：2023/4/10 07:05 下午
 * 创 建 人：wang-xu
 */
public class RealTopic08 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String S = in.nextLine();
        String L = in.nextLine();
        if (S.isEmpty() || S.length() > 100 || S.length() < 1){
            System.out.println("input error");
        }
        if (L.isEmpty() || L.length() > 500*1000 || L.length() < 1){
            System.out.println("input error");
        }
        if (L.contains(String.valueOf(S.charAt(S.length()-1)))){
            System.out.println(L.indexOf(S.charAt(S.length()-1)));
        }else {
            System.out.println(-1);
        }
    }
}
